package borge.web.teamspirit.client.panels;

import java.io.Serializable;

import borge.web.teamspirit.client.data.Event;
import borge.web.teamspirit.client.data.Match;
import borge.web.teamspirit.client.data.News;
import borge.web.teamspirit.client.data.TeamPlayer;
import borge.web.teamspirit.client.data.Serie;
import borge.web.teamspirit.client.data.SerieEnums;
import borge.web.teamspirit.client.interfaces.DataProvider;
import borge.web.teamspirit.client.interfaces.MenuEventHandler;
import borge.web.teamspirit.client.interfaces.PanelHandler;
import borge.web.teamspirit.client.interfaces.ServerCallbackHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.servercomm.DBQuery;
import borge.web.teamspirit.client.servercomm.DBQueryResult;
import borge.web.teamspirit.client.servercomm.ServerComm;
import borge.web.teamspirit.client.widgets.ShowSerieWidget;
import borge.web.teamspirit.client.widgets.ShowTabbedDataWidget;

import com.google.gwt.user.client.Window;

public class ShowPanel extends MiddlePanel implements WidgetEventHandler, MenuEventHandler, ServerCallbackHandler{

    private DataProvider iDataProvider;
    private ShowTabbedDataWidget iActiveWidget;
    
    public ShowPanel(/*ServerComm aServerComm,*/ PanelHandler aPanelHandler){
    	super(/*aServerComm,*/ aPanelHandler);
    }
    
    public void setDataProvider(DataProvider aProvider){
        iDataProvider = aProvider;
    }
    
    public void setActiveWidget(ShowTabbedDataWidget aWidget){
        if(iActiveWidget != null)
            remove(iActiveWidget);
        
        iActiveWidget = aWidget;
        iActiveWidget.setWidgetEventHandler(this);
        add(iActiveWidget);
    }
    
    public void handleWidgetEvent(WidgetEventType aEvent){
     
        switch(aEvent){
        case SHOW_PLAYER: {
            
            TeamPlayer player = iDataProvider.getDataObject();
            
            break;
        }
        case SHOW_SERIE:{
            
            Serie serie = iDataProvider.getDataObject();
            //setActiveWidget(new ShowSerieWidget(serie, this));
            break;
        }
        case SHOW_MATCH:{
            
            Match match = iDataProvider.getDataObject();
            
            break;
        }
        case SHOW_NEWS:{
            
            News news = iDataProvider.getDataObject();
            
            break;
        }
        
        case SHOW_EVENT: {
        	
        	Event event = iDataProvider.getDataObject();
        	//ServerComm.getObject(event.getEventQuery(), this);
        	/*
        	Serie serie = new Serie();
        	serie.setDivision("1a");
        	serie.setSeason("HT09");
        	serie.setType(SerieEnums.Type.INDOOR_SERIE.name());
        	serie.setStatus(SerieEnums.Status.ACTIVE.name());
        	setActiveWidget(new ShowSerieWidget(serie, this));
        	*/
        	// call server to get object..
        }
        }
        
    }
    
    public boolean handleMenuEvent(String aLinkText){
        
        /*
        if(aLinkText.equals(Lagsida.getConstants())){
            
        }*/
        
        return false;
    }
    
    public <T extends Serializable> void handleServerCallback(DBQueryResult<T> aResult, CallbackType aType){
        
    }
    
    public void handleServerError(Throwable t){
        Window.alert("Server error: " + t.toString());
    }
}
